<?php
/**
 * Galdic project
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Galdic
 * @package    Galdic
 * @copyright  Copyright (c) 2009 vifito (http://vifito.eu)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Admin_Form_Definition
 * 
 * @package    Galdic
 * @copyright  Copyright (c) 2009 vifito (http://vifito.eu)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Definition.php 1 2009-09-13 00:06:15Z vifito $
 */
class Admin_Form_Definition extends Zend_Form
{
    public function __construct($options=null)
    {
        parent::__construct($options);
        
        $configForms = dirname(__FILE__) . '/forms.xml';        
        $config = new Zend_Config_Xml($configForms, 'definition');
        $this->setConfig($config);
        
        $categories = new Admin_Model_DbTable_Categories();        
        $this->category_id->addMultiOptions( $categories->getHtmlOptions() );
        
        $terms = new Admin_Model_DbTable_Terms();        
        $this->term_id->addMultiOptions( $terms->getHtmlOptions() );
        
        // Submit button
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setAttrib('id', 'submitbutton');        
        $this->addElement($submit);
    }
    
    public function bindPostData($formData)
    {
        $elements = $this->getElements();
        $keys = array_keys($elements);
        $keys = array_diff($keys, array('submit'));
        
        $data = array();
        
        foreach($formData as $key => $value) {
            if(in_array($key, $keys)) {
                $data[$key] = $value;
            }
        }
        
        return $data;
    }
}
